<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $this->load->view('common/head'); ?>

<?php $this->load->view('common/header'); ?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>
                <div class="page-header">
                    <h1>
                        订单新增
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            新增司导订单
                        </small>
                    </h1>
                </div>
                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal" action="<?php echo site_url(X_URL . 'OrderCar/update'); ?>"
                              method="post">
                            <?php echo csrf_hidden(); ?>
                            <input type="hidden" name="order_id" value="<?php if (!empty($order['order_id'])) {
                                echo $order['order_id'];
                            } ?>">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-6"> 订单编号 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="external_order_no" id="external_order_no"
                                           placeholder="订单编号"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['external_order_no'])) {
                                               echo $order['external_order_no'];
                                           } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-6"> 订单来源 </label>
                                <div class="col-sm-9">
                                    <select id="order_from" name="order_from" class="col-xs-10 col-sm-10 select2">
                                        <option value="">可选择</option>
                                        <?php if (isset($order_from)) { ?>
                                            <?php foreach ($order_from as $key => $val) { ?>
                                                <option value="<?php echo $val['id']; ?>"
                                                        <?php if (isset($order) && $order['order_from'] == $val['id']){ ?>selected="selected"<?php } ?> ><?php echo $val['name']; ?>
                                                </option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-4"> 工种类型 </label>
                                <div class="col-sm-9">
                                    <select id="order_type" name="order_type" class="col-xs-10 col-sm-10 select2">
                                        <option value="">可选择</option>
                                        <?php if (isset($order_type)) { ?>
                                            <?php foreach ($order_type as $key => $val) { ?>
                                                <option value="<?php echo $val['id']; ?>"
                                                        <?php if (isset($order) && $order['order_type'] == $val['id']){ ?>selected="selected"<?php } ?> ><?php echo $val['name']; ?>
                                                </option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-4"> 服务类型 </label>
                                <div class="col-sm-9">
                                    <select id="order_service_id" name="order_service_id"
                                            class="col-xs-10 col-sm-10 select2">
                                        <?php if (isset($order_service_type)) { ?>
                                            <?php foreach ($order_service_type as $key => $val) { ?>
                                                <option value="<?php echo $val['id']; ?>"
                                                        <?php if (isset($order) && $order['order_service_id'] == $val['id']){ ?>selected="selected"<?php } ?> ><?php echo $val['name']; ?>
                                                </option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-4"> 接车要求 </label>
                                <div class="col-sm-9">
                                    <select id="car_requirement" name="car_requirement"
                                            class="multiselect col-xs-10 col-sm-10 select2">
                                        <option value="">可选择</option>
                                        <?php if (isset($car_seat_format)) { ?>
                                            <?php foreach ($car_seat_format as $key => $val) { ?>
                                                <option value="<?php echo $val['id']; ?>"
                                                        <?php if (isset($order) && $order['car_requirement'] == $val['id']){ ?>selected="selected"<?php } ?> ><?php echo $val['car_seat']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-6"> 订单价格 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="order_price" id="order_price" placeholder="订单价格" required
                                           class="col-xs-10 col-sm-10" value="<?php if (!empty($order['order_price'])) {
                                        echo $order['order_price'];
                                    } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-6">
                                    航班号/列车号 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="plane_no" id="plane_no" placeholder="航班号/列车号"
                                           class="col-xs-10 col-sm-10" value="<?php if (!empty($order['plane_no'])) {
                                        echo $order['plane_no'];
                                    } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-6"> 出发时间 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="start_time" id="start_time" placeholder="出发时间" required
                                           class="col-xs-10 col-sm-10" value="<?php if (!empty($order['start_time'])) {
                                        echo $order['start_time'];
                                    } ?>" autocomplete="off">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right"
                                       for="form-field-7">出发国家和城市</label>
                                <div class="col-sm-9">
                                    <select name="departure_country" id="departure_country" class="select2" size="1">
                                        <option value="0">请选择国家</option>
                                        <?php if (isset($area) && !empty($area)) { ?>
                                            <?php foreach ($area as $key => $val) { ?>
                                                <option value="<?php echo $val['area_id']; ?>"
                                                        <?php if (isset($order) && $order['departure_country'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                    <select name="departure_city" id="departure_city" class="select2" size="1">
                                        <option value="0">请选择城市</option>
                                        <?php if (isset($city) && !empty($city)) { ?>
                                            <?php foreach ($city as $key => $val) { ?>
                                                <option value="<?php echo $val['area_id']; ?>"
                                                        <?php if (isset($order) && $order['departure_city'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-7">出发具体地址</label>
                                <div class="col-sm-9">
                                    <input type="text" name="departure_address" id="departure_address"
                                           placeholder="出发具体地址"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['departure_address'])) {
                                               echo $order['departure_address'];
                                           } ?>" required>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right"
                                       for="form-field-7">目的国家和城市</label>
                                <div class="col-sm-9">
                                    <select name="destination_country" id="destination_country" class="select2"
                                            size="1">
                                        <option value="0">请选择国家</option>
                                        <?php if (isset($area) && !empty($area)) { ?>
                                            <?php foreach ($area as $key => $val) { ?>
                                                <option value="<?php echo $val['area_id']; ?>"
                                                        <?php if (isset($order) && $order['destination_country'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                    <select name="destination_city" id="destination_city" class="select2" size="1">
                                        <option value="0">请选择城市</option>
                                        <?php if (isset($city) && !empty($city)) { ?>
                                            <?php foreach ($city as $key => $val) { ?>
                                                <option value="<?php echo $val['area_id']; ?>"
                                                        <?php if (isset($order) && $order['destination_city'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right"
                                       for="form-field-7">目的地具体地址</label>
                                <div class="col-sm-9">
                                    <input type="text" name="destination_address" id="destination_address"
                                           placeholder="目的地具体地址" class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['destination_address'])) {
                                               echo $order['destination_address'];
                                           } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-7">乘客数量</label>
                                <div class="col-sm-9">
                                    <input type="text" name="pasengers" id="pasengers" placeholder="乘客数量"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['pasengers'])) {
                                               echo $order['pasengers'];
                                           } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-7">行李描述</label>
                                <div class="col-sm-9">
                                    <input type="text" name="packages" id="packages" placeholder="行李描述"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['packages'])) {
                                               echo $order['packages'];
                                           } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-7">联系电话</label>
                                <div class="col-sm-9">
                                    <input type="text" name="contact_mobile" id="contact_mobile" placeholder="联系电话"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['contact_mobile'])) {
                                               echo $order['contact_mobile'];
                                           } ?>" required>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-7">联系人</label>
                                <div class="col-sm-9">
                                    <input type="text" name="contact_name" id="contact_name" placeholder="联系人"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['contact_name'])) {
                                               echo $order['contact_name'];
                                           } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-7">微信</label>
                                <div class="col-sm-9">
                                    <input type="text" name="contact_wechat" id="contact_wechat" placeholder="微信"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['contact_wechat'])) {
                                               echo $order['contact_wechat'];
                                           } ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-8">
                                    E-mail </label>
                                <div class="col-sm-9">
                                    <input type="email" name="contact_eamil" id="contact_eamil" placeholder="E-mail"
                                           class="col-xs-10 col-sm-10"
                                           value="<?php if (!empty($order['contact_eamil'])) {
                                               echo $order['contact_eamil'];
                                           }; ?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-7">产品</label>
                                <div class="col-sm-9">
                                    <textarea name="routes" id="routes" placeholder="产品" class="col-xs-10 col-sm-10"
                                              rows="5"><?php if (isset($order) && !empty($order)): ?><?php echo $order['routes']; ?><?php endif; ?></textarea>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-2"> 备注</label>
                                <div class="col-sm-9">
                                    <textarea name="remark" id="remark" placeholder="备注" class="col-xs-10 col-sm-10"
                                              rows="5"><?php if (isset($order) && !empty($order)): ?><?php echo $order['remark']; ?><?php endif; ?></textarea>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info" type="submit">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    </div><?php $this->load->view('common/footer'); ?>


<?php $this->load->view('common/footerjs'); ?>
<!-- inline scripts related to this page -->
<?php echo admin_js_url('laydate'); ?>
<script>
    var service_url = "<?php echo site_url('manage/CarService/get_service');?>";
    var area_url = "<?php echo site_url('manage/Area/get_area');?>";
    laydate.render({
        elem: '#start_time' //指定元素
        , type: "datetime"
    });
    $(function () {
        $(".select2").select2();
        var order_service_select2 = $("#order_service_id").select2();
        var departure_city_select2 = $("#departure_city").select2();
        var destination_city_select2 = $("#destination_city").select2();

        $("#order_type").on("select2:select", function (e) {
            console.log($(this).val());
            var p_id = $(this).val();
            if (p_id > 0) {
                $.ajax({
                    method: "GET",
                    url: service_url,
                    data: {p_id: p_id}
                }).done(function (data) {
                    // console.log(data);
                    $("#order_service_id").html(data);
                    order_service_select2.val(0).trigger("change");
                })
            } else {
                $("#order_service_id").html('<option selected="selected" value="0">可选择</option>');
                order_service_select2.val(0).trigger("change");
            }
        });
        $("#departure_country").on("select2:select", function (e) {
            console.log($(this).val());
            var p_id = $(this).val();
            if (p_id > 0) {
                $.ajax({
                    method: "GET",
                    url: area_url,
                    data: {p_id: p_id}
                }).done(function (data) {
                    // console.log(data);
                    $("#departure_city").html(data);
                    departure_city_select2.val(0).trigger("change");
                })
            } else {
                $("#departure_city").html('<option selected="selected" value="0">可选择</option>');
                departure_city_select2.val(0).trigger("change");
            }
        });
        $("#destination_country").on("select2:select", function (e) {
            console.log($(this).val());
            var p_id = $(this).val();
            if (p_id > 0) {
                $.ajax({
                    method: "GET",
                    url: area_url,
                    data: {p_id: p_id}
                }).done(function (data) {
                    // console.log(data);
                    $("#destination_city").html(data);
                    destination_city_select2.val(0).trigger("change");
                })
            } else {
                $("#destination_city").html('<option selected="selected" value="0">可选择</option>');
                destination_city_select2.val(0).trigger("change");
            }
        });
    });
</script>
</body>
</html>
